VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "linearAbstractAndReplace"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'Used to depend on Iterator.cls
Option Explicit

Private iSubjectEndRow As Integer
Private iObjectEndRow As Integer
Private iSubjectColumn As Integer
Private iObjectColumn As Integer
Private iSubjectStartRow As Integer
Private iObjectStartRow As Integer
Private Iter As New Iterator


Function init(subjectColumn As Integer, objectColumn As Integer, subjectEndRow As Integer, objectEndRow As Integer, _
              Optional subjectStartRow As Integer = 1, Optional objectStartRow As Integer = 1)
    iSubjectColumn = subjectColumn
    iObjectColumn = objectColumn
    iSubjectEndRow = subjectEndRow
    iObjectEndRow = objectEndRow
    iSubjectStartRow = subjectStartRow
    iObjectStartRow = objectStartRow
End Function


Sub OutputText(toColumn_ As Integer, Content As String)
    Dim i%, j%
    
    Dim strSubjectArray(), strObjectArray()
    
    Application.ScreenUpdating = False
    strSubjectArray = Range(Cells(iSubjectStartRow, iSubjectColumn), Cells(iSubjectEndRow, iSubjectColumn))
    strSubjectArray = getALine(strSubjectArray, , 1)
    strObjectArray = Range(Cells(iObjectStartRow, iObjectColumn), Cells(iObjectEndRow, iObjectColumn))
    strObjectArray = getALine(strObjectArray, , 1)
    Iter.init strSubjectArray
    For i = LBound(strObjectArray) To UBound(strObjectArray)
        If Iter.isIn(strObjectArray(i)) Then
            Cells(iObjectStartRow - 1 + i, toColumn_).Value = Content
        End If
    Next i
    Application.ScreenUpdating = True
End Sub

Sub ReUseCell(fromColumn_ As Integer, toColumn_ As Integer)
    Dim i%, j%
    
    Dim strSubjectArray(), strObjectArray()
    Application.ScreenUpdating = False
    strSubjectArray = Range(Cells(iSubjectStartRow, iSubjectColumn), Cells(iSubjectEndRow, iSubjectColumn))
    strSubjectArray = getALine(strSubjectArray, , 1)
    strObjectArray = Range(Cells(iObjectStartRow, iObjectColumn), Cells(iObjectEndRow, iObjectColumn))
    strObjectArray = getALine(strObjectArray, , 1)
    Iter.init strSubjectArray
    For i = LBound(strObjectArray) To UBound(strObjectArray)
        If Iter.isIn(strObjectArray(i)) Then
            Cells(iObjectStartRow + i - 1, toColumn_).Value = Cells(iSubjectStartRow - 1 + Iter.index, fromColumn_).Value
        End If
    Next i
    
    Application.ScreenUpdating = True
End Sub

Private Function getALine(arr, Optional Dimensional = 1, Optional ColumnNum = 1)
    'Dimensional 提取行数组还是列数组，一维数组不用提取
    'ColumnNum
    '当Dimensional=1时,提取行值
    '当Dimensional=2时,提取列值
    '最高可以操作2^15(32767)个数组
    
    Dim ArraytoLine(), ArraytoLine1()
    Dim i%
    Select Case Dimensional
    Case 1
        ArraytoLine = Application.index(arr, , ColumnNum)

        ReDim ArraytoLine1(1 To UBound(arr))
        
        For i = 1 To UBound(arr)
            ArraytoLine1(i) = ArraytoLine(i, 1)
        Next i
        
        getALine = ArraytoLine1
    Case 2
        ArraytoLine = Application.index(arr, ColumnNum, 0)
        getALine = ArraytoLine
    End Select
End Function